package com.nbicc.news.service.impl;

import com.nbicc.news.mapper.NewsContentMapper;
import com.nbicc.news.po.NewsContent;
import com.nbicc.news.service.INewsContentService;
import com.nbicc.parent.listener.OnDeleteListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

@Service("NewsContentServiceImpl")
public class NewsContentServiceImpl implements INewsContentService{

    @Autowired
    private NewsContentMapper newsContentMapper;
    @Resource(name = "NewsContentDeleteListenerImpl")
    private OnDeleteListener onDeleteListener;
    @Resource(name = "NewsContentDeleteListenerImpl")
    private OnDeleteListener deleteListener;

    @Override
    public Integer insert(NewsContent o) throws Exception {
        return newsContentMapper.insert(o);
    }

    @Override
    public NewsContent selectById(Number id) {
        return newsContentMapper.selectById(id);
    }

    @Override
    public Integer updateById(Object o) throws Exception {
        return newsContentMapper.updateById(o);
    }

    @Override
    public Integer deleteById(Number id) {
        deleteListener.delete(id , ()->{
            newsContentMapper.deleteById(id);   //富文本真实内容在删除关联图片后  被删除
        });
        return 1;
    }

}
